import orderApi from '@/static/js/enterpriseServer/order.js'
import shopApi from '@/static/js/enterpriseServer/info.js'
import CountDown from "@/components/countDown/countDown.vue";
export default {
	components: {
		CountDown
	},
	data() {
		return {
			orderObj: {},
			orderNo: null,
			//服务商
			serviceObj: {},
			//商品
			shopObj: {},
			pageShow: false,
			pic: [],
			titleColor: '#fff'
		}
	},
	onLoad(e) {
		this.orderNo = e.orderNo
		this.getDetail()
	},
	methods: {
		//获取订单详情
		async getDetail() {
			let res = await orderApi.getOrderView({
				order_no: this.orderNo
			})
			if (res.code === 1) {
				this.orderObj = res.data
				this.getShopDetail(res.data.shop_id)
				this.pageShow = true
			} else {
				this.$tools.msg(res.msg)
			}
		},


		//获取订单商品详情
		async getShopDetail(id) {
			let res = await shopApi.getShopDetail({
				id: id
			})
			if (res.code === 1) {
				this.shopObj = res.data.info
				this.pic = res.data.info.pic.split(',')
				this.serviceObj = res.data.service_info
			} else {
				this.$tools.msg(res.msg)
			}
		},

		//删除订单
		delOrder(val) {
			if (val.status === 0) {
				this.closeOrder(val)
			} else {
				let id = val.id
				let that = this
				uni.showModal({
					title: '温馨提示',
					confirmText: '确认删除',
					confirmColor: "#0177FD",
					cancelColor: '#999',
					cancelText: '再想想',
					content: '确认删除此订单吗？',
					success: function (res) {
						if (res.confirm) {
							orderApi.delOrder({
								order_id: id
							}).then(ots => {
								if (ots.code === 1) {
									that.$tools.msg('删除成功')
									that.$tools.pageBack()
								} else {
									that.$tools.msg(ots.msg)
								}
							})
						}
					}
				})
			}
		},

		closeOrder(val) {
			let id = val.id
			let that = this
			uni.showModal({
				title: '温馨提示',
				confirmText: '确认取消',
				confirmColor: "#0177FD",
				cancelColor: '#999',
				cancelText: '再想想',
				content: '确认取消此订单吗？',
				success: function (res) {
					if (res.confirm) {
						orderApi.closeOrder({
							id: id
						}).then(ots => {
							if (ots.code === 1) {
								that.$tools.msg('取消成功')
								that.$tools.pageBack()
							} else {
								that.$tools.msg(ots.msg)
							}
						})
					}
				}
			})
		},

		//重新购买商品
		goBuyShop(val) {
			if (val.status === 0) {
				uni.navigateTo({
					url: '/enterpriseServer/payment/index/index?orderNo=' + val.order_no
				})
			} else if (val.status === 2) {
				let that = this
				uni.showModal({
					title: '温馨提示',
					confirmColor: '#0177FD',
					confirmText: '确认验收',
					cancelColor: '#999',
					cancelText: '再想想',
					content: '是否确认验收服务',
					success: function (ots) {
						if (ots.confirm) {
							orderApi.sureOrder({
								order_id: val.id,
								status: 3
							}).then(res => {
								if (res.code === 1) {
									that.$tools.msg('验收成功')
									that.$common.pageBack(1)
								} else {
									that.$tools.msg(ots.msg)
								}
							})
						}
					}
				})
			} else {
				uni.redirectTo({
					url: '/enterpriseServer/productInfo/index?id=' + this.shopObj.id
				})
			}
		},

		//复制订单号
		copyOrder() {
			uni.setClipboardData({
				data: this.orderNo,
				success: function () {
					this.$tools.msg('复制成功')
				}
			})
		},

		//跳转服务商咨询
		goContact() {
			if (!uni.getStorageSync('token')) {
				this.$common.handleToken()
				return
			}
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo.id == this.serviceObj.user_id) {
				this.$tools.msg('不能与自己聊天')
				return
			}
			uni.setStorageSync("to_zim_userid", this.serviceObj.user_id);
			uni.navigateTo({
				url: '/enterpriseServer/chatRoom/index?id=' + this.serviceObj.user_id
			})
		},

	}
}